package br.unisul.sintatico;

import java.io.*;
import java.util.*;

public class FileUtils {

	public static List<String> readTextFromJar(String s) {
		InputStream is = null;
		BufferedReader br = null;
		String line;
		ArrayList<String> list = new ArrayList<String>();

		try {
			is = FileUtils.class.getResourceAsStream(s);
			br = new BufferedReader(new InputStreamReader(is));
			while (null != (line = br.readLine())) {
				list.add(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
				if (is != null)
					is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	public static String [][] toArray(int linhas, int colunas, String s){
		String[][] sn = new String[linhas][colunas];
		try {
			InputStream is = FileUtils.class.getResourceAsStream(s);
			BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			for (int i = 0; i < linhas; i++) {
					String linha = reader.readLine();
					StringTokenizer st = new StringTokenizer(linha);
					int j = 0;
					while (st.hasMoreTokens()) {
						sn[i][j] = st.nextToken();
						j++;
					}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sn;
	}

	public static void main(String args[]) throws IOException {
		String[][] matrizTemp = FileUtils.toArray(36, 53, "/matriz_parse.txt");
		for (int i = 0; i < matrizTemp.length; i++) {
			System.out.println(matrizTemp[i][0]);	
		}
	}
}
